-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Laplacian calculation in spectral partitioning #2568
base: branch-25.04
Are you sure you want to change the base?
Conversation
Also partially answers #379, though we may want additional testing beyond what is provided here. |
In the previous implementation of spectral partitioning, the eigenvalue computation was actually performed on the original adjacency matrix, not the graph Laplacian thereof. This change provides a utility for computing the graph Laplacian, which is then fed into the new implementation of the Lanczos solver. An additional test is provided to ensure that the end-to-end spectral partitioning quality is as expected.
99698bd
to
de85257
Compare
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Will, great work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given Victor approved, I’d like to make sure we are properly hiding implementation detail APIs and publicly exposing public APIs so this doesn’t get merged accidentally.
* Note that for non-symmetric matrices, the out-degree Laplacian is returned. | ||
*/ | ||
template <typename ElementType, typename IndptrType, typename IndicesType, typename NZType> | ||
auto compute_graph_laplacian( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick comment about detail
: In RAFT, we follow the pattern where the public header is a shim layer to the detail API. The logic here would be contained in the detail
namespace as well. For example:
header.cuh:
void foo () {
detail::foo();
}
detail/header.cuh:
namespace detail {
void foo_kernel() {
}
void foo() {
// all checks and logic
foo_kernel<<< >>> ();
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's correct. The publicly facing layer would be responsible for things like input validation (if necessary) but all the guts should be hidden in detail. We've gotten strict about this because we've been bitten too many times by exposing the impl details in the public APIs. RAFT being header-only requires us to be more disciplined and strict with the separation.
These changes enable the use of the new Lanczos solver for spectral partitioning. This solver gives the correct eigenvalues in some cases where the old solver did not, but a previous attempt to introduce this led to a downstream breakage because the Laplacian was not being calculated correctly in the spectral partitioning logic.
In this PR, we introduce a new
compute_graph_laplacian
function to correctly generate a new CSR matrix representing the graph Laplacian of the input CSR-formatted adjacency matrix. This resolves #2419. This function is used in the spectral partition function to obtain the correct partitioning using the new Lanczos solver. This eliminates all internal uses ofcomputeSmallestEigenvectors
, the old Lanczos implementation, which should allow it to be removed after a deprecation cycle for downstream consumers. This will in turn allow us to resolve #313.Note that the originally-reported breakage from the previous attempt to switch to the new Lanczos solver was used to create the test confirming correct functionality of the current PR.
This PR is marked as a bugfix because it unblocks usage of the corrected Lanczos implementation. It is based on and requires PR #2541, and it will be marked as draft until that PR is merged.